'''
Created on 30/01/2013

@author: Milo
'''

def find(f, seq):
    k = -1
    for item in seq:
        k = k+1
        if f == item: 
            return k
    return 0

from BibTeXParser import  BibTeXParser
parser = BibTeXParser()
result = parser.parse("C:\\Users\\Milo\\Workspace\\Mendelay-to-Maltego\\test.bib")

for r in result:

    print "Hello"
    result.pop()
    biblography = result.pop()
    print biblography
    print biblography['author']
    authors = biblography['author'].split()
    print authors
    
    #Type specific hack
    i = 0
    done = False
    while i != -1:
        i = 0
        j = find('and', authors)
        print j
        if j == 0:
            j = len(authors)
            done = True
        print j
        lastname = authors[i]
        firsnameslist = authors[i+1:j]
        firstnames = ""
        for name in firsnameslist:
            firstnames = firstnames + name + " "
        #Remove last space
        firstnames = firstnames[:len(firstnames)-1]
        lastname = lastname.replace(",", "")
        print firstnames
        print lastname
        authors = authors[j+1:]
        #Case of last part
        if done:
            i = -1
    
    
    
